package banner

import (
	"errors"
	"regexp"
)

//当前只支持a-zA-Z0-9的字体

// 字体类型
const (
	FONT_DEFAULT = iota
)

type Font interface {
	Show(ban string) string
	parse()
}

type Banner struct {
	fontType int
	font     Font
}

func NewDefaultBanner() *Banner {
	ban := &Banner{fontType: FONT_DEFAULT}
	ban.parse()
	return ban
}

func (b *Banner) Get(ban string) (string, error) {
	// 正则表达式校验字符串是否正常
	matcher, err := regexp.Compile("[a-zA-Z0-9?-]*")
	if err != nil {
		return "", err
	}
	m := matcher.Match([]byte(ban))
	if !m {
		return "", errors.New("banner text not match, must be a-zA-Z0-9?-")
	}
	return b.font.Show(ban), nil
}

func (b *Banner) parse() {
	var font Font
	switch b.fontType {
	case FONT_DEFAULT:
		font = &DefaultFont{}
	}
	font.parse()
	b.font = font
}
